package Metier;

public class Voiture {
	private int 	_positionX;
	private int 	_positionY;
	private double 	_angleDirection;
	private int 	_vitesse;
	private SimMap 	_map;
	
	public Voiture(int pPositionX, int pPositionY, double pDirection, int pVitesse, SimMap map){
		/*_positionX	= 0;
		_positionY	= 0;
		_angleDirection	= 0.0;
		_vitesse	= 10;*/
		
		this._positionX=pPositionX;
		this._positionY=pPositionY;
		this._angleDirection=pDirection;
		this._vitesse=pVitesse;
		this._map = map;
	}
	
	public int getPositionX() {
		return _positionX;
	}
	
	public void setPositionX(int posX) {
		this._positionX = posX;
	}
	
	public int getPositionY() {
		return _positionY;
	}

	public void setPositionY(int posY) {
		this._positionY = posY;
	}
	
	public double getDirection() {
		return _angleDirection;
	}
	
	public void setDirection(double angle) {
		if (this.getVitesse()!=0){
			this._angleDirection = angle;
		}
	}
	
	public int getVitesse() {
		return _vitesse;
	}
	
	public void setVitesse(int vitesse) {
		this._vitesse = vitesse;
	}
	
	public SimMap getSimMap() {
		return _map;
	}
	
	public void bouger(int pTemps) {
		
		int distance = _vitesse * pTemps;		
		int futurePositionX = this.getPositionX();
		int futurePositionY = this.getPositionX();	
		

		futurePositionX += Math.cos((_angleDirection/180)*Math.PI)*distance;
		futurePositionY += Math.sin((_angleDirection/180)*Math.PI)*distance;	
		if(peutBouger(futurePositionX,futurePositionY)){
			setPositionX(futurePositionX);
			setPositionY(futurePositionY);
		}
		else{
			moveToLimit();
		}
	}

	private void moveToLimit() {
		// TODO Auto-generated method stub		
	}

	private boolean peutBouger(int futurePositionX, int futurePositionY) {
		
		if(_map.isInMap(futurePositionX,futurePositionY)){
			return true;
		}
		else{
			return false;
		}
	}	
	
	/*
	public void accelerer() {
		++ _vitesse;
	}
	public void decelerer() {
		-- _vitesse;
		if(_positionY > _map.getHeight() * _map.getScale()){
			_positionY = _map.getHeight() * _map.getScale();
			this._vitesse = 0;
		}
	}*/
}
